Skip to content

Replace socket.io-client imports with a local type shim in echo.d.ts#529

Merged
taylorotwell merged 2 commits into
laravel:2.xfrom
lazerg:fix/optional-socketio-peer-types
Jun 24, 2026
Merged

Replace socket.io-client imports with a local type shim in echo.d.ts#529
taylorotwell merged 2 commits into
laravel:2.xfrom
lazerg:fix/optional-socketio-peer-types

Conversation

@lazerg

@lazerg lazerg commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Since v2.3.7, the compiled dist/echo.d.ts unconditionally imports Socket and io from socket.io-client. Users who only use Reverb or Pusher never install that package, so TypeScript fails on those imports when skipLibCheck is false.

The root cause is that socketio-channel.ts and socketio-connector.ts import from socket.io-client, and vite-plugin-dts (with rollupTypes: true) inlines those module references into the rolled-up declaration file.

This PR adds a minimal local type shim (src/socketio-types.ts) that declares the small subset of Socket.io types Laravel Echo actually uses — SocketIoSocket, SocketIoManager, and SocketIoFunction. The two connector/channel files and typings/window.d.ts are updated to import from the shim instead of from socket.io-client. The real socket.io-client types satisfy these interfaces, so nothing changes for users who do have the package installed.

After this change, dist/echo.d.ts no longer contains any import … from 'socket.io-client' line. Verified by temporarily removing the package from node_modules and running tsc --noEmit — no errors. All existing tests still pass.

Fixes #528

@taylorotwell taylorotwell merged commit 7abe2fe into laravel:2.x Jun 24, 2026
1 check passed
@lazerg lazerg deleted the fix/optional-socketio-peer-types branch June 25, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot find module 'socket.io-client' or its corresponding type declarations

2 participants